home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5891 < prev    next >
Encoding:
Text File  |  1996-08-05  |  925 b   |  43 lines

  1. Path: news.kreonet.re.kr!usenet
  2. From: jwhahn@cair.kaist.ac.kr (Jung Hahn)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: ???Recursion and strings
  5. Date: Wed, 07 Feb 1996 11:23:20 GMT
  6. Organization: Applied Database Labs, K.A.I.S.T
  7. Message-ID: <31188b9a.12102227@news.kreonet.re.kr>
  8. References: <4f44fg$74u@upsidedown.MTS.Net>
  9. NNTP-Posting-Host: swine.kaist.ac.kr
  10. X-Newsreader: Forte Agent .99d/32.168
  11.  
  12. On Mon, 05 Feb 1996 07:26:43 GMT, bwilliam@MTS.Net (George) wrote:
  13.  
  14. >How do I write a recursive function to print a string  using only
  15. >printf and %c to print it out.
  16. >
  17. >George at bwilliam@MTS.Net
  18. >
  19.  
  20. #include <stdio.h>
  21.  
  22. foo( char *s, int len)
  23. {
  24. static int count=0;
  25.  
  26.     if ( count++ < len) {
  27.         printf( "%c", *s++);
  28.         foo( s, len);
  29.         }
  30. }
  31.  
  32. void main( void)
  33. {
  34.     char *t = "Hello World\n";
  35.  
  36.     foo( t, strlen(t));
  37. }    
  38. ___________
  39.  
  40.     Name:  Jung w. Hahn
  41.     Elm:   jwhahn@cair.kaist.ac.kr
  42.     Phone: 042-869-2959
  43.